package com.jeesite.modules.digitalize.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.jeesite.modules.digitalize.entity.dto.digitalizeComponentNote.*;
import com.jeesite.modules.digitalize.entity.vo.OptionSelectVo;
import com.jeesite.modules.digitalize.entity.vo.digitalizeComponentNote.DigitalizeComponentNoteShareDetailVo;
import com.jeesite.modules.digitalize.entity.vo.digitalizeComponentNote.DigitalizeComponentNoteShareVo;
import com.jeesite.modules.digitalize.entity.vo.digitalizeComponentNote.DigitalizeComponentNoteVo;
import com.jeesite.modules.digitalize.entity.vo.digitalizeComponentNote.ShortChainVo;
import com.jeesite.modules.digitalize.service.DigitalizeComponentNoteService;
import com.jeesite.modules.digitalize.service.DigitalizeComponentNoteShareService;
import com.jeesite.modules.digitalize.util.response.ResultVo;
import com.jeesite.modules.sys.utils.UserUtils;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "数字-[视点|批注|标签]管理")
@RestController
@RequestMapping("${adminPath}/digitalize/note/")
public class DigitalizeComponentNoteController extends ApiController {

    @Resource
    private DigitalizeComponentNoteService digitalizeComponentNoteService;
    @Resource
    private DigitalizeComponentNoteShareService digitalizeComponentNoteShareService;

    @ApiOperation("版本下拉选")
    @GetMapping("versionOptionSelect")
    public ResultVo<List<OptionSelectVo>> versionOptionSelect(@Validated DigitalizeComponentNoteQueryDto queryDto) {
        return digitalizeComponentNoteService.versionOptionSelect(queryDto);
    }

    @ApiOperation("创建人下拉选")
    @GetMapping("createOptionSelect")
    public ResultVo<List<OptionSelectVo>> createOptionSelect(@Validated DigitalizeComponentNoteQueryDto queryDto) {
        return digitalizeComponentNoteService.createOptionSelect(queryDto);
    }

    @ApiOperation("列表[视点|批注|标签]")
    @GetMapping("list")
    public ResultVo<List<DigitalizeComponentNoteVo>> selectAll(@Validated DigitalizeComponentNoteQueryDto queryDto) {
        return digitalizeComponentNoteService.selectAll(queryDto);
    }

    @ApiOperation("详情[视点|批注|标签]")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("{id}")
    public ResultVo<DigitalizeComponentNoteVo> selectOne(@PathVariable Long id) {
        return digitalizeComponentNoteService.selectOne(id);
    }

    @ApiOperation("新增[视点|批注|标签]")
    @PostMapping("add")
    public ResultVo<Object> add(@RequestBody @Validated DigitalizeComponentNoteDto dto) {
        return digitalizeComponentNoteService.add(dto);
    }

    @ApiOperation("重命名[视点|批注|标签]")
    @PostMapping("edit")
    public ResultVo<Object> edit(@RequestBody @Validated DigitalizeComponentNoteEditDto dto) {
        return digitalizeComponentNoteService.edit(dto);
    }

    @ApiOperation("删除[视点|批注|标签]")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Long", paramType = "path")
    @PostMapping("delete/{id}")
    public ResultVo<Object> delete(@PathVariable Long id) {
        return ResultVo.success(digitalizeComponentNoteService.removeById(id));
    }

    @PostMapping("share/{id}")
    @ApiImplicitParam(name = "id", value = "视点id", required = true, dataType = "Long", paramType = "path")
    @ApiOperation("点击分享")
    public ResultVo<ShortChainVo> share(@PathVariable Long id) {
        return digitalizeComponentNoteShareService.share(id);
    }

    @PostMapping("share/setPwd/{id}")
    @ApiImplicitParam(name = "id", value = "分享id", required = true, dataType = "Long", paramType = "path")
    @ApiOperation("设置密码")
    public ResultVo<ShortChainVo> getPwd(@PathVariable Long id) {
        return digitalizeComponentNoteShareService.getPwd(id);
    }

    @PostMapping("share/cancelPwd/{id}")
    @ApiImplicitParam(name = "id", value = "分享", required = true, dataType = "Long", paramType = "path")
    @ApiOperation("取消密码")
    public ResultVo<ShortChainVo> cancelPwd(@PathVariable Long id) {
        return digitalizeComponentNoteShareService.cancelPwd(id);
    }

    @PostMapping("share/cancel/{id}")
    @ApiImplicitParam(name = "id", value = "分享", required = true, dataType = "Long", paramType = "path")
    @ApiOperation("取消分享")
    public ResultVo<Object> shareCancel(@PathVariable Long id) {
        return digitalizeComponentNoteShareService.shareCancel(id);
    }

    @PostMapping("share/setDate")
    @ApiOperation("设置到期时间")
    public ResultVo<ShortChainVo> setDate(@RequestBody @Validated ShareSetDateDto dto) {
        return digitalizeComponentNoteShareService.setDate(dto);
    }

    @GetMapping("share/list")
    @ApiOperation("分享的列表")
    public ResultVo<List<DigitalizeComponentNoteShareVo>> shareList() {
        return digitalizeComponentNoteShareService.shareList(UserUtils.getUser());
    }

    @GetMapping("showShare")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "shortChain", value = "短链", required = true, dataType = "String", paramType = "param"),
            @ApiImplicitParam(name = "password", value = "密码", dataType = "String", paramType = "param")
    })
    @ApiResponses({
            @ApiResponse(code = 3001, message = "该分享为加密，请输入密码"),
            @ApiResponse(code = 3002, message = "分享已过期"),
            @ApiResponse(code = 3003, message = "分享密码错误")
    })
    @ApiOperation("查看分享")
    public ResultVo<DigitalizeComponentNoteShareDetailVo> showShare(@RequestParam String shortChain, @RequestParam(required = false) String password) {
        return digitalizeComponentNoteShareService.showShare(shortChain, password);
    }


}

